import 'dart:convert';
import 'package:flutter/material.dart';

import '../http/base_http.dart';

/// 获取验证码图片（base64）
/// 返回 base64 字符串（不含 data:image/gif;base64, 前缀）
class LoginReq {
  //
  static Future<Map<String, dynamic>> getCodeImg() async {
    final response = await apiClient.get(Uri.parse('/captchaImage'));
    return jsonDecode(response.body);
  }

  static Future<Map<String, dynamic>> login(
    Map<String, dynamic> loginBody,
  ) async {
    final response = await apiClient.post(
      Uri.parse('/login'),
      body: jsonEncode(loginBody),
    );
    return jsonDecode(response.body);
  }

  static Future<Map<String, dynamic>> loginWithPhone(
    Map<String, dynamic> loginBody,
  ) async {
    final response = await apiClient.post(
      Uri.parse('/mobileLogin'),
      body: jsonEncode(loginBody),
    );
    return jsonDecode(response.body);
  }

  static Future<Map<String, dynamic>> getPhoneCaptcha() async {
    final response = await apiClient.get(
      Uri.parse('/phoneCaptcha'),
      // body: jsonEncode(loginBody),
    );
    return jsonDecode(response.body);
  }

  static Future<Map<String, dynamic>> postPhoneCaptcha(
    Map<String, dynamic> loginBody,
  ) async {
    debugPrint('loginBody: $loginBody');
    final response = await apiClient.post(
      Uri.parse('/phoneCaptcha'),
      body: jsonEncode(loginBody),
    );
    debugPrint('response: ${response.body}');
    return jsonDecode(response.body);
  }
}
